package com.ssyt.hiring.easyui;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.ssyt.hiring.common.util.DBUtil;

public class TestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public TestServlet() {
		super();
	}

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String command = request.getParameter("command");
		if ("listMenu".equals(command)) {
			listMenu(request, response);
		}
	}

	private void listMenu(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		int id = 0;
		String idStr = request.getParameter("id");
		if (idStr != null) {
			id = Integer.parseInt(idStr);
		}

		List<MenuEntity> menuList = DBUtil.executeQuery(MenuEntity.class,
				"SELECT * FROM menu WHERE pid=?", id);
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().print(JSON.toJSONString(menuList));
	}
}
